/*
 *                    _ooOoo_
 *                   o8888888o
 *                   88" . "88
 *                   (| -_- |)
 *                   O\  =  /O
 *                ____/`- -'\____
 *              .'  \\|     |//  `.
 *             /  \\|||  :  |||//  \
 *            /  _||||| -:- |||||-  \
 *            |   | \\\  -  /// |   |
 *            | \_|  ''\- -/''  |   |
 *            \  .-\__  `-`  ___/-. /
 *          ___`. .'  /- . -\  `. . __
 *       ."" '<  `.___\_<|>_/___.'  >'"".
 *      | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *      \  \ `-.   \_ __\ /__ _/   .-` /  /
 * ======`-.____`-.___\_____/___.-`____.-'======
 *                    `=- -='
 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 *           佛祖保佑       永无BUG
 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 */

package com.softeem.starwars.panel;

import com.softeem.starwars.frame.MainFrame;
import com.softeem.starwars.utils.ImageLoader;
import com.softeem.starwars.utils.Settings;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

/**
 * @Author mrchai 2020/4/6 14:31
 */
public class HelpPanel extends JPanel implements ActionListener {

    private BufferedImage logoImg;
    private int lw;
    private int lh;
    private JLabel helpText;
    private JButton btnStart;
    private MainFrame main;


    public HelpPanel(MainFrame main){
        this.main = main;
        setLayout(null);
        setBackground(Color.BLACK);
        logoImg = ImageLoader.load("logo.png");
        lw = logoImg.getWidth();
        lh = logoImg.getHeight();

        helpText = new JLabel(Settings.HELP_TEXT);
        helpText.setFont(new Font("黑体",Font.PLAIN,25));
        helpText.setForeground(Color.WHITE);
        helpText.setBounds(50,50,860,400);

        btnStart = new JButton("开始游戏");
        btnStart.setBounds(50,450,860,40);
        btnStart.setBackground(new Color(255,79,25));
        btnStart.setForeground(new Color(255,255,255));
        btnStart.setFont(new Font("微软雅黑",Font.PLAIN,20));
        //设置边框
        btnStart.setBorder(BorderFactory.createLineBorder(new Color(255,79,25)));
        //去除按钮中文本的聚焦状态
        btnStart.setFocusPainted(false);
        btnStart.setActionCommand("start");
        btnStart.addActionListener(this);

        add(helpText);
        add(btnStart);
    }



    @Override
    public void paint(Graphics g) {
        super.paint(g);
        g.drawImage(logoImg, Settings.WIDTH-lw-20,20,lw,lh,null);
        g.setFont(new Font("黑体",Font.PLAIN,30));
        g.setColor(Color.WHITE);
        g.drawString("游戏帮助:",50,50);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        switch(e.getActionCommand()){
            case "start":
                this.setVisible(false);
                GamePanel gp = new GamePanel(main);
                main.add(gp);
                //设置游戏面板聚焦（否则按键事件绑定无效）
                gp.requestFocus();
                break;
        }
    }
}
